﻿var complain = "other/Complain.html";

//投诉建议
var constactsCallback_complain = myApp.onPageInit('complain', function (page) {

    //删除滚动后重新添加滚动
    var flag_InfiniteScroll = true;
    //是否需要滚动加载
    var flag_needScroll = true;
    //滚动事件只执行一次
    var flag_execute = false;
    var currobj = null;
    var errorinfo = "";
    var ct = new Array()
    ct[0] = "建议"
    ct[1] = "投诉"
    var at = new Array()
    at[0] = "服务态度"
    at[1] = "办事效率"
    at[2] = "收费计费"
    at[3] = "便携程度"
    at[4] = "公开程度"
    at[5] = "按章办事"

    $$('#complainType').click(function () {
        currobj = $$(this);
        var html = "<div class='picker-modal picker-1'>" +
                        "<div class='toolbar'>" +
                            "<div class='toolbar-inner'>" +
                                "<div class='left'>" +
                                    "<a href='#' class='close-picker'>取消</a></div>" +
                                "<div class='right'>" +
                                    "<a href='#' ptype='1' class='close-picker'>完成</a></div>" +
                            "</div>" +
                        "</div>" +
                        "<div class='picker-modal-inner'>" +
                            "<div class='content-block'><ul>";
        for (var i = 0; i < ct.length; i++) {
            html += ("<li>" +
                        "<label  class='label-radio item-content'>" +
                        "<input  type='radio' name='my-radio' text='" + ct[i] + "' value='" + i + "'>" +
                            "<div class='item-media'>" +
                            "<i class='icon icon-form-checkbox'></i>" +
                        "</div>" +
                        "<div class='item-inner'>" +
                            "<div class='item-title'>" + ct[i] + "</div>" +
                        "</div>" +
                        "</label>" +
                    "</li>");
        }
        html += "       </ul></div>" +
                                "</div>" +
                            "</div>";
        myApp.pickerModal(html);
        selectoption()
    })
    $$('#appealType').click(function () {
        currobj = $$(this);
        var html = "<div class='picker-modal picker-1'>" +
                        "<div class='toolbar'>" +
                            "<div class='toolbar-inner'>" +
                                "<div class='left'>" +
                                    "<a href='#' class='close-picker'>取消</a></div>" +
                                "<div class='right'>" +
                                    "<a href='#' ptype='1' class='close-picker'>完成</a></div>" +
                            "</div>" +
                        "</div>" +
                        "<div class='picker-modal-inner'>" +
                            "<div class='content-block'><ul>";
        for (var i = 0; i < at.length; i++) {
            html += ("<li>" +
                    "<label  class='label-radio item-content'>" +
                    "<input  type='radio' name='my-radio' text='" + at[i] + "' value='" + i + "'>" +
                        "<div class='item-media'>" +
                        "<i class='icon icon-form-checkbox'></i>" +
                    "</div>" +
                    "<div class='item-inner'>" +
                        "<div class='item-title'>" + at[i] + "</div>" +
                    "</div>" +
                    "</label>" +
                "</li>");
        }
        html += "       </ul></div>" +
                                "</div>" +
                            "</div>";
        myApp.pickerModal(html);
        selectoption()
    })
    function selectoption() {
        $$('.close-picker').on('click', function () {
            if ($$(this).innerText != "取消") {
                var t = "";
                var s = "";
                currobj.find('.checkvalue').html("");
                currobj.find('.checkvalue').attr('val', '');
                $$('input[type="radio"]:checked').each(function (i, v) {
                    t += $$(v).attr('text') + "+";
                    s += $$(v).attr('value') + "+";
                })
                currobj.find('.checkvalue').html(t != "" ? t.substring(0, t.length - 1) : t);
                currobj.find('.checkvalue').attr('val', (s != "" ? s.substring(0, s.length - 1) : s));
            }
            currobj = null;
        })
    }

    $$('.save').click(function () {
        checkvalue()
        if (errorinfo != "") {
            myApp.alert(errorinfo); return false
        }

        var time = new Date();
        // 程序计时的月从0开始取值后+1
        var m = time.getMonth() + 1;
        var t = time.getFullYear() + "-" + m + "-"
         + time.getDate() + " " + time.getHours() + ":"
         + time.getMinutes() + ":" + time.getSeconds();

        var content = new Object();
        content.type = 20;
        var complain = new Object();
        complain.Title = $$('#txttitle').val();
        complain.Content = $$('#txtcontent').val();
        complain.Type = $$('.checkvalue').eq(0).attr('val');
        complain.UserName = $$('#txtname').val();
        complain.UserPhone = $$('#txtPhone').val();
        complain.CreateTime = t;
        content.complain = complain;

        var conditionParams = JSON.stringify(
               content
            );

        $$.ajax({
            url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.COMPLAIN,
            crossDomain: true,
            data: { "content": conditionParams },
            dataType: "jsonp",
            method: "POST",
            success: function (data, status) {
                myApp.alert('提交成功!', '', function () {
                    window.location.reload();
                });
            },
            error: function (xhr, status) {
                // alert(xhr)
            }
        });

    })

    function checkvalue() {
        errorinfo = "";
        $$('.checkvalue').each(function (i, v) {
            if (($$(v).attr('val') == "" || $$(v).attr('val') == "undefined") && i == 0) {
                errorinfo = "请选择反馈类型"
            } else if (($$(v).attr('val') == "" || $$(v).attr('val') == "undefined") && i == 1) {
                errorinfo = "请选择诉求关键字"
            }
            return false
        })
        if (errorinfo != "") return
        $$('input[id^=txt]').each(function (i, v) {
            if ($$(v).val() == "") {
                errorinfo = "请填写完整资料"
                return false
            }
        })
    }

})


/* 初始化  */
function initData() {
    var href = window.location.href;
    if (href.indexOf(complain) > -1) {
        constactsCallback_complain.trigger();
    }
}

initData();